package ru.ccfit.nsu.g7204.dronov.adPlatform;

import ru.ccfit.nsu.g7204.dronov.adPlatform.Banners.Banner;
import ru.ccfit.nsu.g7204.dronov.adPlatform.Banners.dao.BannerDao;
import ru.ccfit.nsu.g7204.dronov.adPlatform.system.db.DBConnectionHolder;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Drongo
 * Date: 22.03.11
 * Time: 15:28
 * To change this template use File | Settings | File Templates.
 */
public class BannersFormController implements BannersFormListener{

    private BannerDao dao;
    private DBConnectionHolder dbConnectionHolder;

    public BannersFormController(DBConnectionHolder dbConnectionHolder) {
        dao =new BannerDao(dbConnectionHolder);
        this.dbConnectionHolder = dbConnectionHolder;
    }

    public void delBanner(long id) {
        dao.delBanner(id);
    }

    public void delAll() {
        dao.delAll();
    }

    public Object[] getBannerList() {
        List<Banner> banners= dao.getBanners();
        if (banners==null || banners.size()==0)
            return null;
        return dao.getBanners().toArray();
    }

    public void addBanner(String info) {
        dao.addBanner(info);
    }

    public void edit(Banner banner) {
        BannerDetailsFormController bannerDetailsFormController= new BannerDetailsFormController(banner, dbConnectionHolder);
        bannerDetailsFormController.setFeatureListSupporter(new FeaturesDBManager(dbConnectionHolder));
        BannerDetailsForm detailsForm=new BannerDetailsForm(bannerDetailsFormController);
    }

    public void updateDbInfo(DBConnectionHolder dbConnectionHolder)
    {
        dao =new BannerDao(dbConnectionHolder);
        this.dbConnectionHolder = dbConnectionHolder;
    }
}
